

<!DOCTYPE html>
<html class="writer-html5" lang="en" >
<head>
  <meta charset="utf-8" />
  
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  
  <title>mindspore.numpy.logic_ops &mdash; MindSpore master documentation</title>
  

  
  <link rel="stylesheet" href="../../../_static/css/theme.css" type="text/css" />
  <link rel="stylesheet" href="../../../_static/pygments.css" type="text/css" />

  
  

  
  

  

  
  <!--[if lt IE 9]>
    <script src="../../../_static/js/html5shiv.min.js"></script>
  <![endif]-->
  
    
      <script type="text/javascript" id="documentation_options" data-url_root="../../../" src="../../../_static/documentation_options.js"></script>
        <script src="../../../_static/jquery.js"></script>
        <script src="../../../_static/underscore.js"></script>
        <script src="../../../_static/doctools.js"></script>
        <script src="../../../_static/language_data.js"></script>
        <script async="async" src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js?config=TeX-AMS-MML_HTMLorMML"></script>
    
    <script type="text/javascript" src="../../../_static/js/theme.js"></script>

    
    <link rel="index" title="Index" href="../../../genindex.html" />
    <link rel="search" title="Search" href="../../../search.html" /> 
</head>

<body class="wy-body-for-nav">

   
  <div class="wy-grid-for-nav">
    
    <nav data-toggle="wy-nav-shift" class="wy-nav-side">
      <div class="wy-side-scroll">
        <div class="wy-side-nav-search" >
          

          
            <a href="../../../index.html" class="icon icon-home"> MindSpore
          

          
          </a>

          
            
            
          

          
<div role="search">
  <form id="rtd-search-form" class="wy-form" action="../../../search.html" method="get">
    <input type="text" name="q" placeholder="Search docs" />
    <input type="hidden" name="check_keywords" value="yes" />
    <input type="hidden" name="area" value="default" />
  </form>
</div>

          
        </div>

        
        <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation">
          
            
            
              
            
            
              <p class="caption"><span class="caption-text">MindSpore Python API</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../../../api_python/mindspore.html">mindspore</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../api_python/mindspore.common.initializer.html">mindspore.common.initializer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../api_python/mindspore.communication.html">mindspore.communication</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../api_python/mindspore.compression.html">mindspore.compression</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../api_python/mindspore.context.html">mindspore.context</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../api_python/mindspore.dataset.html">mindspore.dataset</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../api_python/mindspore.dataset.audio.html">mindspore.dataset.audio</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../api_python/mindspore.dataset.config.html">mindspore.dataset.config</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../api_python/mindspore.dataset.text.html">mindspore.dataset.text</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../api_python/mindspore.dataset.transforms.html">mindspore.dataset.transforms</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../api_python/mindspore.dataset.vision.html">mindspore.dataset.vision</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../api_python/mindspore.mindrecord.html">mindspore.mindrecord</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../api_python/mindspore.nn.html">mindspore.nn</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../api_python/mindspore.nn.probability.html">mindspore.nn.probability</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../api_python/mindspore.nn.transformer.html">mindspore.nn.transformer</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../api_python/mindspore.numpy.html">mindspore.numpy</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../api_python/mindspore.ops.html">mindspore.ops</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../api_python/mindspore.parallel.html">mindspore.parallel</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../api_python/mindspore.parallel.nn.html">mindspore.parallel.nn</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../api_python/mindspore.profiler.html">mindspore.profiler</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../api_python/mindspore.scipy.html">mindspore.scipy</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../api_python/mindspore.train.html">mindspore.train</a></li>
<li class="toctree-l1"><a class="reference internal" href="../../../api_python/mindspore.boost.html">mindspore.boost</a></li>
</ul>
<p class="caption"><span class="caption-text">MindSpore C++ API</span></p>
<ul>
<li class="toctree-l1"><a class="reference external" href="https://www.mindspore.cn/lite/api/zh-CN/master/api_cpp/mindspore.html">MindSpore Lite↗</a></li>
</ul>

            
          
        </div>
        
      </div>
    </nav>

    <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">

      
      <nav class="wy-nav-top" aria-label="top navigation">
        
          <i data-toggle="wy-nav-top" class="fa fa-bars"></i>
          <a href="../../../index.html">MindSpore</a>
        
      </nav>


      <div class="wy-nav-content">
        
        <div class="rst-content">
        
          

















<div role="navigation" aria-label="breadcrumbs navigation">

  <ul class="wy-breadcrumbs">
    
      <li><a href="../../../index.html" class="icon icon-home"></a> &raquo;</li>
        
          <li><a href="../../index.html">Module code</a> &raquo;</li>
        
      <li>mindspore.numpy.logic_ops</li>
    
    
      <li class="wy-breadcrumbs-aside">
        
      </li>
    
  </ul>

  
  <hr/>
</div>
          <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article">
           <div itemprop="articleBody">
            
  <h1>Source code for mindspore.numpy.logic_ops</h1><div class="highlight"><pre>
<span></span><span class="c1"># Copyright 2021 Huawei Technologies Co., Ltd</span>
<span class="c1">#</span>
<span class="c1"># Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);</span>
<span class="c1"># you may not use this file except in compliance with the License.</span>
<span class="c1"># You may obtain a copy of the License at</span>
<span class="c1">#</span>
<span class="c1"># http://www.apache.org/licenses/LICENSE-2.0</span>
<span class="c1">#</span>
<span class="c1"># Unless required by applicable law or agreed to in writing, software</span>
<span class="c1"># distributed under the License is distributed on an &quot;AS IS&quot; BASIS,</span>
<span class="c1"># WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.</span>
<span class="c1"># See the License for the specific language governing permissions and</span>
<span class="c1"># limitations under the License.</span>
<span class="c1"># ============================================================================</span>
<span class="sd">&quot;&quot;&quot;logical operations, the function docs are adapted from Numpy API.&quot;&quot;&quot;</span>


<span class="kn">from</span> <span class="nn">..ops</span> <span class="kn">import</span> <span class="n">functional</span> <span class="k">as</span> <span class="n">F</span>
<span class="kn">from</span> <span class="nn">..common</span> <span class="kn">import</span> <span class="n">dtype</span> <span class="k">as</span> <span class="n">mstype</span>
<span class="kn">from</span> <span class="nn">..common</span> <span class="kn">import</span> <span class="n">Tensor</span>

<span class="kn">from</span> <span class="nn">.math_ops</span> <span class="kn">import</span> <span class="n">_apply_tensor_op</span><span class="p">,</span> <span class="n">absolute</span>
<span class="kn">from</span> <span class="nn">.array_creations</span> <span class="kn">import</span> <span class="n">zeros</span><span class="p">,</span> <span class="n">ones</span><span class="p">,</span> <span class="n">empty</span><span class="p">,</span> <span class="n">asarray</span>
<span class="kn">from</span> <span class="nn">.utils</span> <span class="kn">import</span> <span class="n">_check_input_tensor</span><span class="p">,</span> <span class="n">_to_tensor</span><span class="p">,</span> <span class="n">_isnan</span>
<span class="kn">from</span> <span class="nn">.utils_const</span> <span class="kn">import</span> <span class="n">_raise_type_error</span><span class="p">,</span> <span class="n">_is_shape_empty</span><span class="p">,</span> <span class="n">_infer_out_shape</span><span class="p">,</span> <span class="n">_check_same_type</span><span class="p">,</span> \
    <span class="n">_check_axis_type</span><span class="p">,</span> <span class="n">_canonicalize_axis</span><span class="p">,</span> <span class="n">_can_broadcast</span><span class="p">,</span> <span class="n">_isscalar</span>


<div class="viewcode-block" id="not_equal"><a class="viewcode-back" href="../../../api_python/numpy/mindspore.numpy.not_equal.html#mindspore.numpy.not_equal">[docs]</a><span class="k">def</span> <span class="nf">not_equal</span><span class="p">(</span><span class="n">x1</span><span class="p">,</span> <span class="n">x2</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Returns (x1 != x2) element-wise.</span>

<span class="sd">    Note:</span>
<span class="sd">        Numpy arguments `out`, `where`, `casting`, `order`, `subok`, `signature`,</span>
<span class="sd">        and `extobj` are not supported.</span>

<span class="sd">    Args:</span>
<span class="sd">        x1 (Tensor): First input tensor to be compared.</span>
<span class="sd">        x2 (Tensor): Second input tensor to be compared.</span>
<span class="sd">        dtype (:class:`mindspore.dtype`, optional): Defaults to None. Overrides the dtype of the</span>
<span class="sd">            output Tensor.</span>

<span class="sd">    Returns:</span>
<span class="sd">       Tensor or scalar, element-wise comparison of `x1` and `x2`. Typically of type</span>
<span class="sd">       bool, unless `dtype` is passed. This is a scalar if both `x1` and `x2` are</span>
<span class="sd">       scalars.</span>

<span class="sd">    Raises:</span>
<span class="sd">        TypeError: If the input is not a tensor.</span>

<span class="sd">    Supported Platforms:</span>
<span class="sd">        ``Ascend`` ``GPU`` ``CPU``</span>

<span class="sd">    Examples:</span>
<span class="sd">        &gt;&gt;&gt; import mindspore.numpy as np</span>
<span class="sd">        &gt;&gt;&gt; a = np.asarray([1, 2])</span>
<span class="sd">        &gt;&gt;&gt; b = np.asarray([[1, 3],[1, 4]])</span>
<span class="sd">        &gt;&gt;&gt; print(np.not_equal(a, b))</span>
<span class="sd">        [[False  True]</span>
<span class="sd">        [False  True]]</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">_check_input_tensor</span><span class="p">(</span><span class="n">x1</span><span class="p">,</span> <span class="n">x2</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">_apply_tensor_op</span><span class="p">(</span><span class="n">F</span><span class="o">.</span><span class="n">not_equal</span><span class="p">,</span> <span class="n">x1</span><span class="p">,</span> <span class="n">x2</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="n">dtype</span><span class="p">)</span></div>


<div class="viewcode-block" id="less_equal"><a class="viewcode-back" href="../../../api_python/numpy/mindspore.numpy.less_equal.html#mindspore.numpy.less_equal">[docs]</a><span class="k">def</span> <span class="nf">less_equal</span><span class="p">(</span><span class="n">x1</span><span class="p">,</span> <span class="n">x2</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Returns the truth value of ``(x1 &lt;= x2)`` element-wise.</span>

<span class="sd">    Note:</span>
<span class="sd">        Numpy arguments `out`, `where`, `casting`, `order`, `subok`, `signature`,</span>
<span class="sd">        and `extobj` are not supported.</span>

<span class="sd">    Args:</span>
<span class="sd">        x1 (Tensor): Input array.</span>
<span class="sd">        x2 (Tensor): Input array. If ``x1.shape != x2.shape``, they must be</span>
<span class="sd">            broadcastable to a common shape (which becomes the shape of the output).</span>
<span class="sd">        dtype (:class:`mindspore.dtype`, optional): Defaults to None. Overrides the dtype of the</span>
<span class="sd">            output Tensor.</span>

<span class="sd">    Returns:</span>
<span class="sd">       Tensor or scalar, element-wise comparison of `x1` and `x2`. Typically of type</span>
<span class="sd">       bool, unless `dtype` is passed. This is a scalar if both `x1` and `x2` are</span>
<span class="sd">       scalars.</span>

<span class="sd">    Supported Platforms:</span>
<span class="sd">        ``Ascend`` ``GPU`` ``CPU``</span>

<span class="sd">    Examples:</span>
<span class="sd">        &gt;&gt;&gt; import mindspore.numpy as np</span>
<span class="sd">        &gt;&gt;&gt; output = np.less_equal(np.array([4, 2, 1]), np.array([2, 2, 2]))</span>
<span class="sd">        &gt;&gt;&gt; print(output)</span>
<span class="sd">        [False  True  True]</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">_check_input_tensor</span><span class="p">(</span><span class="n">x1</span><span class="p">,</span> <span class="n">x2</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">_apply_tensor_op</span><span class="p">(</span><span class="n">F</span><span class="o">.</span><span class="n">tensor_le</span><span class="p">,</span> <span class="n">x1</span><span class="p">,</span> <span class="n">x2</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="n">dtype</span><span class="p">)</span></div>


<div class="viewcode-block" id="less"><a class="viewcode-back" href="../../../api_python/numpy/mindspore.numpy.less.html#mindspore.numpy.less">[docs]</a><span class="k">def</span> <span class="nf">less</span><span class="p">(</span><span class="n">x1</span><span class="p">,</span> <span class="n">x2</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Returns the truth value of ``(x1 &lt; x2)`` element-wise.</span>

<span class="sd">    Note:</span>
<span class="sd">        Numpy arguments `out`, `where`, `casting`, `order`, `subok`, `signature`,</span>
<span class="sd">        and `extobj` are not supported.</span>

<span class="sd">    Args:</span>
<span class="sd">        x1 (Tensor): input array.</span>
<span class="sd">        x2 (Tensor): Input array. If ``x1.shape != x2.shape``, they must be</span>
<span class="sd">            broadcastable to a common shape (which becomes the shape of the output).</span>
<span class="sd">        dtype (:class:`mindspore.dtype`, optional): Defaults to None. Overrides the dtype of the</span>
<span class="sd">            output Tensor.</span>

<span class="sd">    Returns:</span>
<span class="sd">       Tensor or scalar, element-wise comparison of `x1` and `x2`. Typically of type</span>
<span class="sd">       bool, unless `dtype` is passed. This is a scalar if both `x1` and `x2` are</span>
<span class="sd">       scalars.</span>

<span class="sd">    Supported Platforms:</span>
<span class="sd">        ``Ascend`` ``GPU`` ``CPU``</span>

<span class="sd">    Examples:</span>
<span class="sd">        &gt;&gt;&gt; import mindspore.numpy as np</span>
<span class="sd">        &gt;&gt;&gt; output = np.less(np.array([1, 2]), np.array([2, 2]))</span>
<span class="sd">        &gt;&gt;&gt; print(output)</span>
<span class="sd">        [ True False]</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">return</span> <span class="n">_apply_tensor_op</span><span class="p">(</span><span class="n">F</span><span class="o">.</span><span class="n">tensor_lt</span><span class="p">,</span> <span class="n">x1</span><span class="p">,</span> <span class="n">x2</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="n">dtype</span><span class="p">)</span></div>


<div class="viewcode-block" id="greater_equal"><a class="viewcode-back" href="../../../api_python/numpy/mindspore.numpy.greater_equal.html#mindspore.numpy.greater_equal">[docs]</a><span class="k">def</span> <span class="nf">greater_equal</span><span class="p">(</span><span class="n">x1</span><span class="p">,</span> <span class="n">x2</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Returns the truth value of ``(x1 &gt;= x2)`` element-wise.</span>

<span class="sd">    Note:</span>
<span class="sd">        Numpy arguments `out`, `where`, `casting`, `order`, `subok`, `signature`,</span>
<span class="sd">        and `extobj` are not supported.</span>

<span class="sd">    Args:</span>
<span class="sd">        x1 (Tensor): Input array.</span>
<span class="sd">        x2 (Tensor): Input array. If ``x1.shape != x2.shape``, they must be</span>
<span class="sd">            broadcastable to a common shape (which becomes the shape of the output).</span>
<span class="sd">        dtype (:class:`mindspore.dtype`, optional): Defaults to None. Overrides the dtype of the</span>
<span class="sd">            output Tensor.</span>

<span class="sd">    Returns:</span>
<span class="sd">       Tensor or scalar, element-wise comparison of `x1` and `x2`. Typically of type</span>
<span class="sd">       bool, unless `dtype` is passed. This is a scalar if both `x1` and `x2` are</span>
<span class="sd">       scalars.</span>

<span class="sd">    Supported Platforms:</span>
<span class="sd">        ``Ascend`` ``GPU`` ``CPU``</span>

<span class="sd">    Examples:</span>
<span class="sd">        &gt;&gt;&gt; import mindspore.numpy as np</span>
<span class="sd">        &gt;&gt;&gt; output = np.greater_equal(np.array([4, 2, 1]), np.array([2, 2, 2]))</span>
<span class="sd">        &gt;&gt;&gt; print(output)</span>
<span class="sd">        [ True  True False]</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">return</span> <span class="n">_apply_tensor_op</span><span class="p">(</span><span class="n">F</span><span class="o">.</span><span class="n">tensor_ge</span><span class="p">,</span> <span class="n">x1</span><span class="p">,</span> <span class="n">x2</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="n">dtype</span><span class="p">)</span></div>


<div class="viewcode-block" id="greater"><a class="viewcode-back" href="../../../api_python/numpy/mindspore.numpy.greater.html#mindspore.numpy.greater">[docs]</a><span class="k">def</span> <span class="nf">greater</span><span class="p">(</span><span class="n">x1</span><span class="p">,</span> <span class="n">x2</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Returns the truth value of ``(x1 &gt; x2)`` element-wise.</span>

<span class="sd">    Note:</span>
<span class="sd">        Numpy arguments `out`, `where`, `casting`, `order`, `subok`, `signature`,</span>
<span class="sd">        and `extobj` are not supported.</span>

<span class="sd">    Args:</span>
<span class="sd">        x1 (Tensor): Input array.</span>
<span class="sd">        x2 (Tensor): Input array. If ``x1.shape != x2.shape``, they must be</span>
<span class="sd">            broadcastable to a common shape (which becomes the shape of the output).</span>
<span class="sd">        dtype (:class:`mindspore.dtype`, optional): Defaults to None. Overrides the dtype of the</span>
<span class="sd">            output Tensor.</span>

<span class="sd">    Returns:</span>
<span class="sd">       Tensor or scalar, element-wise comparison of `x1` and `x2`. Typically of type</span>
<span class="sd">       bool, unless `dtype` is passed. This is a scalar if both `x1` and `x2` are</span>
<span class="sd">       scalars.</span>

<span class="sd">    Supported Platforms:</span>
<span class="sd">        ``Ascend`` ``GPU`` ``CPU``</span>

<span class="sd">    Examples:</span>
<span class="sd">        &gt;&gt;&gt; import mindspore.numpy as np</span>
<span class="sd">        &gt;&gt;&gt; output = np.greater(np.array([4, 2]), np.array([2, 2]))</span>
<span class="sd">        &gt;&gt;&gt; print(output)</span>
<span class="sd">        [ True False]</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">return</span> <span class="n">_apply_tensor_op</span><span class="p">(</span><span class="n">F</span><span class="o">.</span><span class="n">tensor_gt</span><span class="p">,</span> <span class="n">x1</span><span class="p">,</span> <span class="n">x2</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="n">dtype</span><span class="p">)</span></div>


<div class="viewcode-block" id="equal"><a class="viewcode-back" href="../../../api_python/numpy/mindspore.numpy.equal.html#mindspore.numpy.equal">[docs]</a><span class="k">def</span> <span class="nf">equal</span><span class="p">(</span><span class="n">x1</span><span class="p">,</span> <span class="n">x2</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Returns the truth value of ``(x1 == x2)`` element-wise.</span>

<span class="sd">    Note:</span>
<span class="sd">        Numpy arguments `out`, `where`, `casting`, `order`, `subok`, `signature`,</span>
<span class="sd">        and `extobj` are not supported.</span>

<span class="sd">    Args:</span>
<span class="sd">        x1 (Tensor): Input array.</span>
<span class="sd">        x2 (Tensor): Input array. If ``x1.shape != x2.shape``, they must be</span>
<span class="sd">            broadcastable to a common shape (which becomes the shape of the output).</span>
<span class="sd">        dtype (:class:`mindspore.dtype`, optional): Defaults to None. Overrides the dtype of the</span>
<span class="sd">            output Tensor.</span>

<span class="sd">    Returns:</span>
<span class="sd">       Tensor or scalar, element-wise comparison of `x1` and `x2`. Typically of type</span>
<span class="sd">       bool, unless `dtype` is passed. This is a scalar if both `x1` and `x2` are</span>
<span class="sd">       scalars.</span>

<span class="sd">    Supported Platforms:</span>
<span class="sd">        ``Ascend`` ``GPU`` ``CPU``</span>

<span class="sd">    Examples:</span>
<span class="sd">        &gt;&gt;&gt; import mindspore.numpy as np</span>
<span class="sd">        &gt;&gt;&gt; output = np.equal(np.array([0, 1, 3]), np.arange(3))</span>
<span class="sd">        &gt;&gt;&gt; print(output)</span>
<span class="sd">        [ True  True False]</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">return</span> <span class="n">_apply_tensor_op</span><span class="p">(</span><span class="n">F</span><span class="o">.</span><span class="n">equal</span><span class="p">,</span> <span class="n">x1</span><span class="p">,</span> <span class="n">x2</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="n">dtype</span><span class="p">)</span></div>


<div class="viewcode-block" id="isfinite"><a class="viewcode-back" href="../../../api_python/numpy/mindspore.numpy.isfinite.html#mindspore.numpy.isfinite">[docs]</a><span class="k">def</span> <span class="nf">isfinite</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Tests element-wise for finiteness (not infinity or not Not a Number).</span>

<span class="sd">    The result is returned as a boolean array.</span>

<span class="sd">    Note:</span>
<span class="sd">        Numpy arguments `out`, `where`, `casting`, `order`, `subok`, `signature`,</span>
<span class="sd">        and `extobj` are not supported.</span>
<span class="sd">        On GPU, the supported dtypes are np.float16, and np.float32.</span>

<span class="sd">    Args:</span>
<span class="sd">        x (Tensor): Input values.</span>
<span class="sd">        dtype (:class:`mindspore.dtype`, optional): Defaults to None. Overrides the dtype of the</span>
<span class="sd">            output Tensor.</span>

<span class="sd">    Returns:</span>
<span class="sd">       Tensor or scalar, true where `x` is not positive infinity, negative infinity,</span>
<span class="sd">       or NaN; false otherwise. This is a scalar if `x` is a scalar.</span>

<span class="sd">    Supported Platforms:</span>
<span class="sd">        ``Ascend`` ``GPU`` ``CPU``</span>

<span class="sd">    Examples:</span>
<span class="sd">        &gt;&gt;&gt; import mindspore.numpy as np</span>
<span class="sd">        &gt;&gt;&gt; output = np.isfinite(np.array([np.inf, 1., np.nan]).astype(&#39;float32&#39;))</span>
<span class="sd">        &gt;&gt;&gt; print(output)</span>
<span class="sd">        [False  True False]</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">return</span> <span class="n">_apply_tensor_op</span><span class="p">(</span><span class="n">F</span><span class="o">.</span><span class="n">isfinite</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="n">dtype</span><span class="p">)</span></div>


<div class="viewcode-block" id="isnan"><a class="viewcode-back" href="../../../api_python/numpy/mindspore.numpy.isnan.html#mindspore.numpy.isnan">[docs]</a><span class="k">def</span> <span class="nf">isnan</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Tests element-wise for NaN and return result as a boolean array.</span>

<span class="sd">    Note:</span>
<span class="sd">        Numpy arguments `out`, `where`, `casting`, `order`, `subok`, `signature`,</span>
<span class="sd">        and `extobj` are not supported.</span>
<span class="sd">        Only np.float32 is currently supported.</span>

<span class="sd">    Args:</span>
<span class="sd">        x (Tensor): Input values.</span>
<span class="sd">        dtype (:class:`mindspore.dtype`, optional): Defaults to None. Overrides the dtype of the</span>
<span class="sd">            output Tensor.</span>

<span class="sd">    Returns:</span>
<span class="sd">       Tensor or scalar, true where `x` is NaN, false otherwise. This is a scalar if</span>
<span class="sd">       `x` is a scalar.</span>

<span class="sd">    Supported Platforms:</span>
<span class="sd">        ``GPU`` ``CPU``</span>

<span class="sd">    Examples:</span>
<span class="sd">        &gt;&gt;&gt; import mindspore.numpy as np</span>
<span class="sd">        &gt;&gt;&gt; output = np.isnan(np.array(np.nan, np.float32))</span>
<span class="sd">        &gt;&gt;&gt; print(output)</span>
<span class="sd">        True</span>
<span class="sd">        &gt;&gt;&gt; output = np.isnan(np.array(np.inf, np.float32))</span>
<span class="sd">        &gt;&gt;&gt; print(output)</span>
<span class="sd">        False</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">return</span> <span class="n">_apply_tensor_op</span><span class="p">(</span><span class="n">_isnan</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="n">dtype</span><span class="p">)</span></div>


<span class="k">def</span> <span class="nf">_isinf</span><span class="p">(</span><span class="n">x</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Computes isinf without applying keyword arguments.&quot;&quot;&quot;</span>
    <span class="n">shape</span> <span class="o">=</span> <span class="n">F</span><span class="o">.</span><span class="n">shape</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
    <span class="n">zeros_tensor</span> <span class="o">=</span> <span class="n">zeros</span><span class="p">(</span><span class="n">shape</span><span class="p">,</span> <span class="n">mstype</span><span class="o">.</span><span class="n">float32</span><span class="p">)</span>
    <span class="n">ones_tensor</span> <span class="o">=</span> <span class="n">ones</span><span class="p">(</span><span class="n">shape</span><span class="p">,</span> <span class="n">mstype</span><span class="o">.</span><span class="n">float32</span><span class="p">)</span>
    <span class="n">not_inf</span> <span class="o">=</span> <span class="n">F</span><span class="o">.</span><span class="n">isfinite</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
    <span class="n">is_nan</span> <span class="o">=</span> <span class="n">_isnan</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
    <span class="n">res</span> <span class="o">=</span> <span class="n">F</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="n">not_inf</span><span class="p">,</span> <span class="n">zeros_tensor</span><span class="p">,</span> <span class="n">ones_tensor</span><span class="p">)</span>
    <span class="n">res</span> <span class="o">=</span> <span class="n">F</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="n">is_nan</span><span class="p">,</span> <span class="n">zeros_tensor</span><span class="p">,</span> <span class="n">res</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">F</span><span class="o">.</span><span class="n">cast</span><span class="p">(</span><span class="n">res</span><span class="p">,</span> <span class="n">mstype</span><span class="o">.</span><span class="n">bool_</span><span class="p">)</span>


<div class="viewcode-block" id="isinf"><a class="viewcode-back" href="../../../api_python/numpy/mindspore.numpy.isinf.html#mindspore.numpy.isinf">[docs]</a><span class="k">def</span> <span class="nf">isinf</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Tests element-wise for positive or negative infinity.</span>

<span class="sd">    Returns a boolean array of the same shape as `x`, True where ``x == +/-inf``, otherwise False.</span>

<span class="sd">    Note:</span>
<span class="sd">        Numpy arguments `out`, `where`, `casting`, `order`, `subok`, `signature`,</span>
<span class="sd">        and `extobj` are not supported.</span>
<span class="sd">        Only np.float32 is currently supported.</span>

<span class="sd">    Args:</span>
<span class="sd">        x (Tensor): Input values.</span>
<span class="sd">        dtype (:class:`mindspore.dtype`, optional): Defaults to None. Overrides the dtype of the</span>
<span class="sd">            output Tensor.</span>

<span class="sd">    Returns:</span>
<span class="sd">       Tensor or scalar, true where `x` is positive or negative infinity, false</span>
<span class="sd">       otherwise. This is a scalar if `x` is a scalar.</span>

<span class="sd">    Supported Platforms:</span>
<span class="sd">        ``GPU`` ``CPU``</span>

<span class="sd">    Examples:</span>
<span class="sd">        &gt;&gt;&gt; import mindspore.numpy as np</span>
<span class="sd">        &gt;&gt;&gt; output = np.isinf(np.array(np.inf, np.float32))</span>
<span class="sd">        &gt;&gt;&gt; print(output)</span>
<span class="sd">        True</span>
<span class="sd">        &gt;&gt;&gt; output = np.isinf(np.array([np.inf, -np.inf, 1.0, np.nan], np.float32))</span>
<span class="sd">        &gt;&gt;&gt; print(output)</span>
<span class="sd">        [ True  True False False]</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">return</span> <span class="n">_apply_tensor_op</span><span class="p">(</span><span class="n">_isinf</span><span class="p">,</span> <span class="n">x</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="n">dtype</span><span class="p">)</span></div>


<span class="k">def</span> <span class="nf">_is_sign_inf</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">fn</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;Tests element-wise for inifinity with sign.&quot;&quot;&quot;</span>
    <span class="n">shape</span> <span class="o">=</span> <span class="n">F</span><span class="o">.</span><span class="n">shape</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
    <span class="n">zeros_tensor</span> <span class="o">=</span> <span class="n">zeros</span><span class="p">(</span><span class="n">shape</span><span class="p">,</span> <span class="n">mstype</span><span class="o">.</span><span class="n">float32</span><span class="p">)</span>
    <span class="n">ones_tensor</span> <span class="o">=</span> <span class="n">ones</span><span class="p">(</span><span class="n">shape</span><span class="p">,</span> <span class="n">mstype</span><span class="o">.</span><span class="n">float32</span><span class="p">)</span>
    <span class="n">not_inf</span> <span class="o">=</span> <span class="n">F</span><span class="o">.</span><span class="n">isfinite</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
    <span class="n">is_sign</span> <span class="o">=</span> <span class="n">fn</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">zeros_tensor</span><span class="p">)</span>
    <span class="n">res</span> <span class="o">=</span> <span class="n">F</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="n">not_inf</span><span class="p">,</span> <span class="n">zeros_tensor</span><span class="p">,</span> <span class="n">ones_tensor</span><span class="p">)</span>
    <span class="n">res</span> <span class="o">=</span> <span class="n">F</span><span class="o">.</span><span class="n">select</span><span class="p">(</span><span class="n">is_sign</span><span class="p">,</span> <span class="n">res</span><span class="p">,</span> <span class="n">zeros_tensor</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">F</span><span class="o">.</span><span class="n">cast</span><span class="p">(</span><span class="n">res</span><span class="p">,</span> <span class="n">mstype</span><span class="o">.</span><span class="n">bool_</span><span class="p">)</span>


<div class="viewcode-block" id="isposinf"><a class="viewcode-back" href="../../../api_python/numpy/mindspore.numpy.isposinf.html#mindspore.numpy.isposinf">[docs]</a><span class="k">def</span> <span class="nf">isposinf</span><span class="p">(</span><span class="n">x</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Tests element-wise for positive infinity, returns result as bool array.</span>

<span class="sd">    Note:</span>
<span class="sd">        Numpy argument `out` is not supported.</span>
<span class="sd">        Only np.float32 is currently supported.</span>

<span class="sd">    Args:</span>
<span class="sd">        x (Tensor): Input values.</span>

<span class="sd">    Returns:</span>
<span class="sd">       Tensor or scalar, true where `x` is positive infinity, false otherwise.</span>
<span class="sd">       This is a scalar if `x` is a scalar.</span>

<span class="sd">    Raises:</span>
<span class="sd">        TypeError: If the input is not a tensor.</span>

<span class="sd">    Supported Platforms:</span>
<span class="sd">        ``GPU`` ``CPU``</span>

<span class="sd">    Examples:</span>
<span class="sd">        &gt;&gt;&gt; import mindspore.numpy as np</span>
<span class="sd">        &gt;&gt;&gt; output = np.isposinf(np.array([-np.inf, 0., np.inf, np.nan], np.float32))</span>
<span class="sd">        &gt;&gt;&gt; print(output)</span>
<span class="sd">        [False False  True False]</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">_check_input_tensor</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">_is_sign_inf</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">F</span><span class="o">.</span><span class="n">tensor_gt</span><span class="p">)</span></div>


<div class="viewcode-block" id="isneginf"><a class="viewcode-back" href="../../../api_python/numpy/mindspore.numpy.isneginf.html#mindspore.numpy.isneginf">[docs]</a><span class="k">def</span> <span class="nf">isneginf</span><span class="p">(</span><span class="n">x</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Tests element-wise for negative infinity, returns result as bool array.</span>

<span class="sd">    Note:</span>
<span class="sd">        Numpy argument `out` is not supported.</span>
<span class="sd">        Only np.float32 is currently supported.</span>

<span class="sd">    Args:</span>
<span class="sd">        x (Tensor): Input values.</span>

<span class="sd">    Returns:</span>
<span class="sd">       Tensor or scalar, true where `x` is negative infinity, false otherwise.</span>
<span class="sd">       This is a scalar if `x` is a scalar.</span>

<span class="sd">    Raises:</span>
<span class="sd">        TypeError: If the input is not a tensor.</span>

<span class="sd">    Supported Platforms:</span>
<span class="sd">        ``GPU`` ``CPU``</span>

<span class="sd">    Examples:</span>
<span class="sd">        &gt;&gt;&gt; import mindspore.numpy as np</span>
<span class="sd">        &gt;&gt;&gt; output = np.isneginf(np.array([-np.inf, 0., np.inf, np.nan], np.float32))</span>
<span class="sd">        &gt;&gt;&gt; print(output)</span>
<span class="sd">        [ True False False False]</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">return</span> <span class="n">_is_sign_inf</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">F</span><span class="o">.</span><span class="n">tensor_lt</span><span class="p">)</span></div>


<div class="viewcode-block" id="isscalar"><a class="viewcode-back" href="../../../api_python/numpy/mindspore.numpy.isscalar.html#mindspore.numpy.isscalar">[docs]</a><span class="k">def</span> <span class="nf">isscalar</span><span class="p">(</span><span class="n">element</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Returns True if the type of element is a scalar type.</span>

<span class="sd">    Note:</span>
<span class="sd">        Only object types recognized by the mindspore parser are supported,</span>
<span class="sd">        which includes objects, types, methods and functions defined within</span>
<span class="sd">        the scope of mindspore. Other built-in types are not supported.</span>

<span class="sd">    Args:</span>
<span class="sd">        element (any): Input argument, can be of any type and shape.</span>

<span class="sd">    Returns:</span>
<span class="sd">        Boolean, True if `element` is a scalar type, False if it is not.</span>

<span class="sd">    Raises:</span>
<span class="sd">        TypeError: If the type of `element` is not supported by mindspore parser.</span>

<span class="sd">    Supported Platforms:</span>
<span class="sd">        ``Ascend`` ``GPU`` ``CPU``</span>

<span class="sd">    Examples:</span>
<span class="sd">        &gt;&gt;&gt; import mindspore.numpy as np</span>
<span class="sd">        &gt;&gt;&gt; output = np.isscalar(3.1)</span>
<span class="sd">        &gt;&gt;&gt; print(output)</span>
<span class="sd">        True</span>
<span class="sd">        &gt;&gt;&gt; output = np.isscalar(np.array(3.1))</span>
<span class="sd">        &gt;&gt;&gt; print(output)</span>
<span class="sd">        False</span>
<span class="sd">        &gt;&gt;&gt; output = np.isscalar(False)</span>
<span class="sd">        &gt;&gt;&gt; print(output)</span>
<span class="sd">        True</span>
<span class="sd">        &gt;&gt;&gt; output = np.isscalar(&#39;numpy&#39;)</span>
<span class="sd">        &gt;&gt;&gt; print(output)</span>
<span class="sd">        True</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">obj_type</span> <span class="o">=</span> <span class="n">F</span><span class="o">.</span><span class="n">typeof</span><span class="p">(</span><span class="n">element</span><span class="p">)</span>
    <span class="k">return</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">obj_type</span><span class="p">,</span> <span class="n">Tensor</span><span class="p">)</span> <span class="ow">and</span> <span class="n">_isscalar</span><span class="p">(</span><span class="n">obj_type</span><span class="p">)</span></div>


<div class="viewcode-block" id="isclose"><a class="viewcode-back" href="../../../api_python/numpy/mindspore.numpy.isclose.html#mindspore.numpy.isclose">[docs]</a><span class="k">def</span> <span class="nf">isclose</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">,</span> <span class="n">rtol</span><span class="o">=</span><span class="mf">1e-05</span><span class="p">,</span> <span class="n">atol</span><span class="o">=</span><span class="mf">1e-08</span><span class="p">,</span> <span class="n">equal_nan</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Returns a boolean tensor where two tensors are element-wise equal within a tolerance.</span>

<span class="sd">    The tolerance values are positive, typically very small numbers. The relative</span>
<span class="sd">    difference (:math:`rtol * abs(b)`) and the absolute difference `atol` are added together</span>
<span class="sd">    to compare against the absolute difference between `a` and `b`.</span>

<span class="sd">    Note:</span>
<span class="sd">        For finite values, isclose uses the following equation to test whether two</span>
<span class="sd">        floating point values are equivalent.</span>
<span class="sd">        :math:`absolute(a - b) &lt;= (atol + rtol * absolute(b))`</span>
<span class="sd">        On Ascend, input arrays containing inf or NaN are not supported.</span>

<span class="sd">    Args:</span>
<span class="sd">        a (Union[Tensor, list, tuple]): Input first tensor to compare.</span>
<span class="sd">        b (Union[Tensor, list, tuple]): Input second tensor to compare.</span>
<span class="sd">        rtol (numbers.Number): The relative tolerance parameter (see Note).</span>
<span class="sd">        atol (numbers.Number): The absolute tolerance parameter (see Note).</span>
<span class="sd">        equal_nan (bool): Whether to compare ``NaN`` as equal. If True, ``NaN`` in</span>
<span class="sd">            `a` will be considered equal to ``NaN`` in `b` in the output tensor.</span>
<span class="sd">            Default: `False`.</span>

<span class="sd">    Returns:</span>
<span class="sd">        A ``bool`` tensor of where `a` and `b` are equal within the given tolerance.</span>

<span class="sd">    Raises:</span>
<span class="sd">        TypeError: If inputs have types not specified above.</span>

<span class="sd">    Supported Platforms:</span>
<span class="sd">        ``Ascend`` ``GPU`` ``CPU``</span>

<span class="sd">    Examples:</span>
<span class="sd">        &gt;&gt;&gt; a = np.array([0,1,2,float(&#39;inf&#39;),float(&#39;inf&#39;),float(&#39;nan&#39;)])</span>
<span class="sd">        &gt;&gt;&gt; b = np.array([0,1,-2,float(&#39;-inf&#39;),float(&#39;inf&#39;),float(&#39;nan&#39;)])</span>
<span class="sd">        &gt;&gt;&gt; print(np.isclose(a, b))</span>
<span class="sd">        [ True  True False False  True False]</span>
<span class="sd">        &gt;&gt;&gt; print(np.isclose(a, b, equal_nan=True))</span>
<span class="sd">        [ True  True False False  True  True]</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">a</span><span class="p">,</span> <span class="n">b</span> <span class="o">=</span> <span class="n">_to_tensor</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">b</span><span class="p">)</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">rtol</span><span class="p">,</span> <span class="p">(</span><span class="nb">int</span><span class="p">,</span> <span class="nb">float</span><span class="p">,</span> <span class="nb">bool</span><span class="p">))</span> <span class="ow">or</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">atol</span><span class="p">,</span> <span class="p">(</span><span class="nb">int</span><span class="p">,</span> <span class="nb">float</span><span class="p">,</span> <span class="nb">bool</span><span class="p">)):</span>
        <span class="n">_raise_type_error</span><span class="p">(</span><span class="s2">&quot;rtol and atol are expected to be numbers.&quot;</span><span class="p">)</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">equal_nan</span><span class="p">,</span> <span class="nb">bool</span><span class="p">):</span>
        <span class="n">_raise_type_error</span><span class="p">(</span><span class="s2">&quot;equal_nan is expected to be bool.&quot;</span><span class="p">)</span>

    <span class="k">if</span> <span class="n">_is_shape_empty</span><span class="p">(</span><span class="n">a</span><span class="o">.</span><span class="n">shape</span><span class="p">)</span> <span class="ow">or</span> <span class="n">_is_shape_empty</span><span class="p">(</span><span class="n">b</span><span class="o">.</span><span class="n">shape</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">empty</span><span class="p">(</span><span class="n">_infer_out_shape</span><span class="p">(</span><span class="n">a</span><span class="o">.</span><span class="n">shape</span><span class="p">,</span> <span class="n">b</span><span class="o">.</span><span class="n">shape</span><span class="p">),</span> <span class="n">dtype</span><span class="o">=</span><span class="n">mstype</span><span class="o">.</span><span class="n">bool_</span><span class="p">)</span>
    <span class="n">rtol</span> <span class="o">=</span> <span class="n">_to_tensor</span><span class="p">(</span><span class="n">rtol</span><span class="p">)</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="s2">&quot;float32&quot;</span><span class="p">)</span>
    <span class="n">atol</span> <span class="o">=</span> <span class="n">_to_tensor</span><span class="p">(</span><span class="n">atol</span><span class="p">)</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="s2">&quot;float32&quot;</span><span class="p">)</span>
    <span class="n">res</span> <span class="o">=</span> <span class="n">absolute</span><span class="p">(</span><span class="n">a</span> <span class="o">-</span> <span class="n">b</span><span class="p">)</span> <span class="o">&lt;=</span> <span class="p">(</span><span class="n">atol</span> <span class="o">+</span> <span class="n">rtol</span> <span class="o">*</span> <span class="n">absolute</span><span class="p">(</span><span class="n">b</span><span class="p">))</span>
    <span class="c1"># infs are treated as equal</span>
    <span class="n">a_posinf</span> <span class="o">=</span> <span class="n">isposinf</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>
    <span class="n">b_posinf</span> <span class="o">=</span> <span class="n">isposinf</span><span class="p">(</span><span class="n">b</span><span class="p">)</span>
    <span class="n">a_neginf</span> <span class="o">=</span> <span class="n">isneginf</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>
    <span class="n">b_neginf</span> <span class="o">=</span> <span class="n">isneginf</span><span class="p">(</span><span class="n">b</span><span class="p">)</span>
    <span class="n">same_inf</span> <span class="o">=</span> <span class="n">F</span><span class="o">.</span><span class="n">logical_or</span><span class="p">(</span><span class="n">F</span><span class="o">.</span><span class="n">logical_and</span><span class="p">(</span><span class="n">a_posinf</span><span class="p">,</span> <span class="n">b_posinf</span><span class="p">),</span> <span class="n">F</span><span class="o">.</span><span class="n">logical_and</span><span class="p">(</span><span class="n">a_neginf</span><span class="p">,</span> <span class="n">b_neginf</span><span class="p">))</span>
    <span class="n">diff_inf</span> <span class="o">=</span> <span class="n">F</span><span class="o">.</span><span class="n">logical_or</span><span class="p">(</span><span class="n">F</span><span class="o">.</span><span class="n">logical_and</span><span class="p">(</span><span class="n">a_posinf</span><span class="p">,</span> <span class="n">b_neginf</span><span class="p">),</span> <span class="n">F</span><span class="o">.</span><span class="n">logical_and</span><span class="p">(</span><span class="n">a_neginf</span><span class="p">,</span> <span class="n">b_posinf</span><span class="p">))</span>
    <span class="n">res</span> <span class="o">=</span> <span class="n">F</span><span class="o">.</span><span class="n">logical_and</span><span class="p">(</span><span class="n">F</span><span class="o">.</span><span class="n">logical_or</span><span class="p">(</span><span class="n">res</span><span class="p">,</span> <span class="n">same_inf</span><span class="p">),</span> <span class="n">F</span><span class="o">.</span><span class="n">logical_not</span><span class="p">(</span><span class="n">diff_inf</span><span class="p">))</span>
    <span class="n">both_nan</span> <span class="o">=</span> <span class="n">F</span><span class="o">.</span><span class="n">logical_and</span><span class="p">(</span><span class="n">_isnan</span><span class="p">(</span><span class="n">a</span><span class="p">),</span> <span class="n">_isnan</span><span class="p">(</span><span class="n">b</span><span class="p">))</span>
    <span class="k">if</span> <span class="n">equal_nan</span><span class="p">:</span>
        <span class="n">res</span> <span class="o">=</span> <span class="n">F</span><span class="o">.</span><span class="n">logical_or</span><span class="p">(</span><span class="n">both_nan</span><span class="p">,</span> <span class="n">res</span><span class="p">)</span>
    <span class="k">else</span><span class="p">:</span>
        <span class="n">res</span> <span class="o">=</span> <span class="n">F</span><span class="o">.</span><span class="n">logical_and</span><span class="p">(</span><span class="n">F</span><span class="o">.</span><span class="n">logical_not</span><span class="p">(</span><span class="n">both_nan</span><span class="p">),</span> <span class="n">res</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">res</span></div>


<div class="viewcode-block" id="in1d"><a class="viewcode-back" href="../../../api_python/numpy/mindspore.numpy.in1d.html#mindspore.numpy.in1d">[docs]</a><span class="k">def</span> <span class="nf">in1d</span><span class="p">(</span><span class="n">ar1</span><span class="p">,</span> <span class="n">ar2</span><span class="p">,</span> <span class="n">invert</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Tests whether each element of a 1-D array is also present in a second array.</span>

<span class="sd">    Returns a boolean array the same length as `ar1` that is True where an element</span>
<span class="sd">    of `ar1` is in `ar2` and False otherwise.</span>

<span class="sd">    Note:</span>
<span class="sd">        Numpy argument `assume_unique` is not supported since the implementation does</span>
<span class="sd">        not rely on the uniqueness of the input arrays.</span>

<span class="sd">    Args:</span>
<span class="sd">        ar1 (Union[int, float, bool, list, tuple, Tensor]): Input array with shape `(M,)`.</span>
<span class="sd">        ar2 (Union[int, float, bool, list, tuple, Tensor]): The values against which</span>
<span class="sd">            to test each value of `ar1`.</span>
<span class="sd">        invert (boolean, optional): If True, the values in the returned array are</span>
<span class="sd">            inverted (that is, False where an element of `ar1` is in `ar2` and True</span>
<span class="sd">            otherwise). Default is False.</span>

<span class="sd">    Returns:</span>
<span class="sd">       Tensor, with shape `(M,)`. The values ``ar1[in1d]`` are in `ar2`.</span>

<span class="sd">    Supported Platforms:</span>
<span class="sd">        ``Ascend`` ``GPU`` ``CPU``</span>

<span class="sd">    Examples:</span>
<span class="sd">        &gt;&gt;&gt; test = np.array([0, 1, 2, 5, 0])</span>
<span class="sd">        &gt;&gt;&gt; states = [0, 2]</span>
<span class="sd">        &gt;&gt;&gt; mask = np.in1d(test, states)</span>
<span class="sd">        &gt;&gt;&gt; print(mask)</span>
<span class="sd">        [ True False  True False  True]</span>
<span class="sd">        &gt;&gt;&gt; mask = np.in1d(test, states, invert=True)</span>
<span class="sd">        &gt;&gt;&gt; print(mask)</span>
<span class="sd">        [False  True False  True False]</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">ar1</span><span class="p">,</span> <span class="n">ar2</span> <span class="o">=</span> <span class="n">_to_tensor</span><span class="p">(</span><span class="n">ar1</span><span class="p">,</span> <span class="n">ar2</span><span class="p">)</span>
    <span class="n">ar1</span> <span class="o">=</span> <span class="n">F</span><span class="o">.</span><span class="n">expand_dims</span><span class="p">(</span><span class="n">ar1</span><span class="o">.</span><span class="n">ravel</span><span class="p">(),</span> <span class="o">-</span><span class="mi">1</span><span class="p">)</span>
    <span class="n">ar2</span> <span class="o">=</span> <span class="n">ar2</span><span class="o">.</span><span class="n">ravel</span><span class="p">()</span>
    <span class="n">included</span> <span class="o">=</span> <span class="n">F</span><span class="o">.</span><span class="n">equal</span><span class="p">(</span><span class="n">ar1</span><span class="p">,</span> <span class="n">ar2</span><span class="p">)</span>
    <span class="c1"># F.reduce_sum only supports float</span>
    <span class="n">res</span> <span class="o">=</span> <span class="n">F</span><span class="o">.</span><span class="n">reduce_sum</span><span class="p">(</span><span class="n">included</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="n">mstype</span><span class="o">.</span><span class="n">float32</span><span class="p">),</span> <span class="o">-</span><span class="mi">1</span><span class="p">)</span><span class="o">.</span><span class="n">astype</span><span class="p">(</span><span class="n">mstype</span><span class="o">.</span><span class="n">bool_</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">invert</span><span class="p">:</span>
        <span class="n">res</span> <span class="o">=</span> <span class="n">F</span><span class="o">.</span><span class="n">logical_not</span><span class="p">(</span><span class="n">res</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">res</span></div>


<div class="viewcode-block" id="isin"><a class="viewcode-back" href="../../../api_python/numpy/mindspore.numpy.isin.html#mindspore.numpy.isin">[docs]</a><span class="k">def</span> <span class="nf">isin</span><span class="p">(</span><span class="n">element</span><span class="p">,</span> <span class="n">test_elements</span><span class="p">,</span> <span class="n">invert</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Calculates element in `test_elements`, broadcasting over `element` only. Returns a</span>
<span class="sd">    boolean array of the same shape as `element` that is True where an element of</span>
<span class="sd">    `element` is in `test_elements` and False otherwise.</span>

<span class="sd">    Note:</span>
<span class="sd">        Numpy argument `assume_unique` is not supported since the implementation does</span>
<span class="sd">        not rely on the uniqueness of the input arrays.</span>

<span class="sd">    Args:</span>
<span class="sd">        element (Union[int, float, bool, list, tuple, Tensor]): Input array.</span>
<span class="sd">        test_elements (Union[int, float, bool, list, tuple, Tensor]): The values against</span>
<span class="sd">            which to test each value of `element`.</span>
<span class="sd">        invert (boolean, optional): If True, the values in the returned array are</span>
<span class="sd">            inverted, as if calculating `element` not in `test_elements`. Default is False.</span>

<span class="sd">    Returns:</span>
<span class="sd">       Tensor, has the same shape as `element`. The values ``element[isin]`` are in</span>
<span class="sd">       `test_elements`.</span>

<span class="sd">    Supported Platforms:</span>
<span class="sd">        ``Ascend`` ``GPU`` ``CPU``</span>

<span class="sd">    Examples:</span>
<span class="sd">        &gt;&gt;&gt; element = 2*np.arange(4).reshape((2, 2))</span>
<span class="sd">        &gt;&gt;&gt; test_elements = [1, 2, 4, 8]</span>
<span class="sd">        &gt;&gt;&gt; mask = np.isin(element, test_elements)</span>
<span class="sd">        &gt;&gt;&gt; print(mask)</span>
<span class="sd">        [[False  True]</span>
<span class="sd">        [ True False]]</span>
<span class="sd">        &gt;&gt;&gt; mask = np.isin(element, test_elements, invert=True)</span>
<span class="sd">        &gt;&gt;&gt; print(mask)</span>
<span class="sd">        [[ True False]</span>
<span class="sd">        [False  True]]</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">element</span> <span class="o">=</span> <span class="n">_to_tensor</span><span class="p">(</span><span class="n">element</span><span class="p">)</span>
    <span class="n">res</span> <span class="o">=</span> <span class="n">in1d</span><span class="p">(</span><span class="n">element</span><span class="p">,</span> <span class="n">test_elements</span><span class="p">,</span> <span class="n">invert</span><span class="o">=</span><span class="n">invert</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">F</span><span class="o">.</span><span class="n">reshape</span><span class="p">(</span><span class="n">res</span><span class="p">,</span> <span class="n">F</span><span class="o">.</span><span class="n">shape</span><span class="p">(</span><span class="n">element</span><span class="p">))</span></div>


<div class="viewcode-block" id="logical_not"><a class="viewcode-back" href="../../../api_python/numpy/mindspore.numpy.logical_not.html#mindspore.numpy.logical_not">[docs]</a><span class="k">def</span> <span class="nf">logical_not</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Computes the truth value of NOT `a` element-wise.</span>

<span class="sd">    Note:</span>
<span class="sd">        Numpy arguments `out`, `where`, `casting`, `order`, `subok`, `signature`, and `extobj` are</span>
<span class="sd">        not supported.</span>

<span class="sd">    Args:</span>
<span class="sd">        a (Tensor): The input tensor whose dtype is bool.</span>
<span class="sd">        dtype (:class:`mindspore.dtype`, optional): Default: :class:`None`. Overrides the dtype of the</span>
<span class="sd">            output Tensor.</span>

<span class="sd">    Returns:</span>
<span class="sd">        Tensor or scalar.</span>
<span class="sd">        Boolean result with the same shape as `a` of the NOT operation on elements of `a`.</span>
<span class="sd">        This is a scalar if `a` is a scalar.</span>

<span class="sd">    Raises:</span>
<span class="sd">        TypeError: If the input is not a tensor or its dtype is not bool.</span>

<span class="sd">    Supported Platforms:</span>
<span class="sd">        ``Ascend`` ``GPU`` ``CPU``</span>

<span class="sd">    Examples:</span>
<span class="sd">        &gt;&gt;&gt; import mindspore.numpy as np</span>
<span class="sd">        &gt;&gt;&gt; a = np.array([True, False])</span>
<span class="sd">        &gt;&gt;&gt; output = np.logical_not(a)</span>
<span class="sd">        &gt;&gt;&gt; print(output)</span>
<span class="sd">        [False  True]</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">return</span> <span class="n">_apply_tensor_op</span><span class="p">(</span><span class="n">F</span><span class="o">.</span><span class="n">logical_not</span><span class="p">,</span> <span class="n">a</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="n">dtype</span><span class="p">)</span></div>


<div class="viewcode-block" id="logical_or"><a class="viewcode-back" href="../../../api_python/numpy/mindspore.numpy.logical_or.html#mindspore.numpy.logical_or">[docs]</a><span class="k">def</span> <span class="nf">logical_or</span><span class="p">(</span><span class="n">x1</span><span class="p">,</span> <span class="n">x2</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Computes the truth value of `x1` OR `x2` element-wise.</span>

<span class="sd">    Note:</span>
<span class="sd">        Numpy arguments `out`, `where`, `casting`, `order`, `subok`, `signature`,</span>
<span class="sd">        and `extobj` are not supported.</span>

<span class="sd">    Args:</span>
<span class="sd">        x1 (Tensor): Input tensor.</span>
<span class="sd">        x2 (Tensor): Input tensor. If ``x1.shape != x2.shape``, they must be</span>
<span class="sd">            broadcastable to a common shape (which becomes the shape of the output).</span>
<span class="sd">        dtype (:class:`mindspore.dtype`, optional): Defaults to None. Overrides the dtype of the</span>
<span class="sd">            output Tensor.</span>

<span class="sd">    Returns:</span>
<span class="sd">       Tensor or scalar, element-wise comparison of `x1` and `x2`. Typically of type</span>
<span class="sd">       bool, unless ``dtype=object`` is passed. This is a scalar if both `x1` and `x2` are</span>
<span class="sd">       scalars.</span>

<span class="sd">    Supported Platforms:</span>
<span class="sd">        ``Ascend`` ``GPU`` ``CPU``</span>

<span class="sd">    Examples:</span>
<span class="sd">        &gt;&gt;&gt; import mindspore.numpy as np</span>
<span class="sd">        &gt;&gt;&gt; x1 = np.array([True, False])</span>
<span class="sd">        &gt;&gt;&gt; x2 = np.array([False, True])</span>
<span class="sd">        &gt;&gt;&gt; output = np.logical_or(x1, x2)</span>
<span class="sd">        &gt;&gt;&gt; print(output)</span>
<span class="sd">        [ True  True]</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">return</span> <span class="n">_apply_tensor_op</span><span class="p">(</span><span class="n">F</span><span class="o">.</span><span class="n">logical_or</span><span class="p">,</span> <span class="n">x1</span><span class="p">,</span> <span class="n">x2</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="n">dtype</span><span class="p">)</span></div>


<div class="viewcode-block" id="logical_and"><a class="viewcode-back" href="../../../api_python/numpy/mindspore.numpy.logical_and.html#mindspore.numpy.logical_and">[docs]</a><span class="k">def</span> <span class="nf">logical_and</span><span class="p">(</span><span class="n">x1</span><span class="p">,</span> <span class="n">x2</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Computes the truth value of `x1` AND `x2` element-wise.</span>

<span class="sd">    Note:</span>
<span class="sd">        Numpy arguments `out`, `where`, `casting`, `order`, `subok`, `signature`,</span>
<span class="sd">        and `extobj` are not supported.</span>

<span class="sd">    Args:</span>
<span class="sd">        x1 (Tensor): Input tensor.</span>
<span class="sd">        x2 (Tensor): Input tensor. If ``x1.shape != x2.shape``, they must be</span>
<span class="sd">            broadcastable to a common shape (which becomes the shape of the output).</span>
<span class="sd">        dtype (:class:`mindspore.dtype`, optional): Defaults to None. Overrides the dtype of the</span>
<span class="sd">            output Tensor.</span>

<span class="sd">    Returns:</span>
<span class="sd">        Tensor or scalar.</span>
<span class="sd">        Boolean result of the logical AND operation applied to the elements of `x1` and `x2`;</span>
<span class="sd">        the shape is determined by broadcasting. This is a scalar if both `x1` and `x2` are scalars.</span>

<span class="sd">    Supported Platforms:</span>
<span class="sd">        ``Ascend`` ``GPU`` ``CPU``</span>

<span class="sd">    Examples:</span>
<span class="sd">        &gt;&gt;&gt; import mindspore.numpy as np</span>
<span class="sd">        &gt;&gt;&gt; x1 = np.array([True, False])</span>
<span class="sd">        &gt;&gt;&gt; x2 = np.array([False, False])</span>
<span class="sd">        &gt;&gt;&gt; output = np.logical_and(x1, x2)</span>
<span class="sd">        &gt;&gt;&gt; print(output)</span>
<span class="sd">        [False False]</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">return</span> <span class="n">_apply_tensor_op</span><span class="p">(</span><span class="n">F</span><span class="o">.</span><span class="n">logical_and</span><span class="p">,</span> <span class="n">x1</span><span class="p">,</span> <span class="n">x2</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="n">dtype</span><span class="p">)</span></div>


<div class="viewcode-block" id="logical_xor"><a class="viewcode-back" href="../../../api_python/numpy/mindspore.numpy.logical_xor.html#mindspore.numpy.logical_xor">[docs]</a><span class="k">def</span> <span class="nf">logical_xor</span><span class="p">(</span><span class="n">x1</span><span class="p">,</span> <span class="n">x2</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Computes the truth value of `x1` XOR `x2`, element-wise.</span>

<span class="sd">    Note:</span>
<span class="sd">        Numpy arguments `out`, `where`, `casting`, `order`, `subok`, `signature`,</span>
<span class="sd">        and `extobj` are not supported.</span>

<span class="sd">    Args:</span>
<span class="sd">        x1 (Tensor): Input tensor.</span>
<span class="sd">        x2 (Tensor): Input tensor. If ``x1.shape != x2.shape``, they must be</span>
<span class="sd">            broadcastable to a common shape (which becomes the shape of the output).</span>
<span class="sd">        dtype (:class:`mindspore.dtype`, optional): Defaults to None. Overrides the dtype of the</span>
<span class="sd">            output Tensor.</span>

<span class="sd">    Returns:</span>
<span class="sd">        Tensor or scalar.</span>
<span class="sd">        Boolean result of the logical AND operation applied to the elements of `x1` and `x2`;</span>
<span class="sd">        the shape is determined by broadcasting. This is a scalar if both `x1` and `x2` are scalars.</span>

<span class="sd">    Supported Platforms:</span>
<span class="sd">        ``Ascend`` ``GPU`` ``CPU``</span>

<span class="sd">    Examples:</span>
<span class="sd">        &gt;&gt;&gt; import mindspore.numpy as np</span>
<span class="sd">        &gt;&gt;&gt; x1 = np.array([True, False])</span>
<span class="sd">        &gt;&gt;&gt; x2 = np.array([False, False])</span>
<span class="sd">        &gt;&gt;&gt; output = np.logical_xor(x1, x2)</span>
<span class="sd">        &gt;&gt;&gt; print(output)</span>
<span class="sd">        [True False]</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">_check_input_tensor</span><span class="p">(</span><span class="n">x1</span><span class="p">)</span>
    <span class="n">_check_input_tensor</span><span class="p">(</span><span class="n">x2</span><span class="p">)</span>
    <span class="n">y1</span> <span class="o">=</span> <span class="n">F</span><span class="o">.</span><span class="n">logical_or</span><span class="p">(</span><span class="n">x1</span><span class="p">,</span> <span class="n">x2</span><span class="p">)</span>
    <span class="n">y2</span> <span class="o">=</span> <span class="n">F</span><span class="o">.</span><span class="n">logical_or</span><span class="p">(</span><span class="n">F</span><span class="o">.</span><span class="n">logical_not</span><span class="p">(</span><span class="n">x1</span><span class="p">),</span> <span class="n">F</span><span class="o">.</span><span class="n">logical_not</span><span class="p">(</span><span class="n">x2</span><span class="p">))</span>
    <span class="k">return</span> <span class="n">_apply_tensor_op</span><span class="p">(</span><span class="n">F</span><span class="o">.</span><span class="n">logical_and</span><span class="p">,</span> <span class="n">y1</span><span class="p">,</span> <span class="n">y2</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="n">dtype</span><span class="p">)</span></div>


<div class="viewcode-block" id="array_equal"><a class="viewcode-back" href="../../../api_python/numpy/mindspore.numpy.array_equal.html#mindspore.numpy.array_equal">[docs]</a><span class="k">def</span> <span class="nf">array_equal</span><span class="p">(</span><span class="n">a1</span><span class="p">,</span> <span class="n">a2</span><span class="p">,</span> <span class="n">equal_nan</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Returns `True` if input arrays have same shapes and all elements equal.</span>

<span class="sd">    Note:</span>
<span class="sd">        In mindspore, a bool tensor is returned instead, since in Graph mode, the</span>
<span class="sd">        value cannot be traced and computed at compile time.</span>

<span class="sd">        Since on Ascend, :class:`nan` is treated differently, currently the argument</span>
<span class="sd">        `equal_nan` is not supported on Ascend.</span>

<span class="sd">    Args:</span>
<span class="sd">        a1/a2 (Union[int, float, bool, list, tuple, Tensor]): Input arrays.</span>
<span class="sd">        equal_nan (bool): Whether to compare NaN&#39;s as equal. Default: `False`.</span>

<span class="sd">    Returns:</span>
<span class="sd">        Scalar bool tensor, value is `True` if inputs are equal, `False` otherwise.</span>

<span class="sd">    Raises:</span>
<span class="sd">        TypeError: If inputs have types not specified above.</span>

<span class="sd">    Supported Platforms:</span>
<span class="sd">        ``GPU`` ``CPU`` ``Ascend``</span>

<span class="sd">    Examples:</span>
<span class="sd">        &gt;&gt;&gt; import mindspore.numpy as np</span>
<span class="sd">        &gt;&gt;&gt; a = [0,1,2]</span>
<span class="sd">        &gt;&gt;&gt; b = [[0,1,2], [0,1,2]]</span>
<span class="sd">        &gt;&gt;&gt; print(np.array_equal(a,b))</span>
<span class="sd">        False</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">a1</span> <span class="o">=</span> <span class="n">asarray</span><span class="p">(</span><span class="n">a1</span><span class="p">)</span>
    <span class="n">a2</span> <span class="o">=</span> <span class="n">asarray</span><span class="p">(</span><span class="n">a2</span><span class="p">)</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">equal_nan</span><span class="p">,</span> <span class="nb">bool</span><span class="p">):</span>
        <span class="n">_raise_type_error</span><span class="p">(</span><span class="s2">&quot;equal_nan must be bool.&quot;</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">a1</span><span class="o">.</span><span class="n">shape</span> <span class="o">==</span> <span class="n">a2</span><span class="o">.</span><span class="n">shape</span><span class="p">:</span>
        <span class="n">res</span> <span class="o">=</span> <span class="n">equal</span><span class="p">(</span><span class="n">a1</span><span class="p">,</span> <span class="n">a2</span><span class="p">)</span>
        <span class="k">if</span> <span class="n">equal_nan</span><span class="p">:</span>
            <span class="n">res</span> <span class="o">=</span> <span class="n">logical_or</span><span class="p">(</span><span class="n">res</span><span class="p">,</span> <span class="n">logical_and</span><span class="p">(</span><span class="n">isnan</span><span class="p">(</span><span class="n">a1</span><span class="p">),</span> <span class="n">isnan</span><span class="p">(</span><span class="n">a2</span><span class="p">)))</span>
        <span class="k">return</span> <span class="n">res</span><span class="o">.</span><span class="n">all</span><span class="p">()</span>
    <span class="k">return</span> <span class="n">_to_tensor</span><span class="p">(</span><span class="kc">False</span><span class="p">)</span></div>


<div class="viewcode-block" id="array_equiv"><a class="viewcode-back" href="../../../api_python/numpy/mindspore.numpy.array_equiv.html#mindspore.numpy.array_equiv">[docs]</a><span class="k">def</span> <span class="nf">array_equiv</span><span class="p">(</span><span class="n">a1</span><span class="p">,</span> <span class="n">a2</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Returns `True` if input arrays are shape consistent and all elements equal.</span>

<span class="sd">    Shape consistent means they are either the same shape, or one input array can</span>
<span class="sd">    be broadcasted to create the same shape as the other one.</span>

<span class="sd">    Note:</span>
<span class="sd">        In mindspore, a bool tensor is returned instead, since in Graph mode, the</span>
<span class="sd">        value cannot be traced and computed at compile time.</span>

<span class="sd">    Args:</span>
<span class="sd">        a1/a2 (Union[int, float, bool, list, tuple, Tensor]): Input arrays.</span>

<span class="sd">    Returns:</span>
<span class="sd">        Scalar bool tensor, value is `True` if inputs are equivalent, `False` otherwise.</span>

<span class="sd">    Raises:</span>
<span class="sd">        TypeError: If inputs have types not specified above.</span>

<span class="sd">    Supported Platforms:</span>
<span class="sd">        ``Ascend`` ``GPU`` ``CPU``</span>

<span class="sd">    Examples:</span>
<span class="sd">        &gt;&gt;&gt; import mindspore.numpy as np</span>
<span class="sd">        &gt;&gt;&gt; a = [0,1,2]</span>
<span class="sd">        &gt;&gt;&gt; b = [[0,1,2], [0,1,2]]</span>
<span class="sd">        &gt;&gt;&gt; print(np.array_equiv(a,b))</span>
<span class="sd">        True</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="n">a1</span> <span class="o">=</span> <span class="n">asarray</span><span class="p">(</span><span class="n">a1</span><span class="p">)</span>
    <span class="n">a2</span> <span class="o">=</span> <span class="n">asarray</span><span class="p">(</span><span class="n">a2</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">_can_broadcast</span><span class="p">(</span><span class="n">a1</span><span class="o">.</span><span class="n">shape</span><span class="p">,</span> <span class="n">a2</span><span class="o">.</span><span class="n">shape</span><span class="p">):</span>
        <span class="k">return</span> <span class="n">equal</span><span class="p">(</span><span class="n">a1</span><span class="p">,</span> <span class="n">a2</span><span class="p">)</span><span class="o">.</span><span class="n">all</span><span class="p">()</span>
    <span class="k">return</span> <span class="n">_to_tensor</span><span class="p">(</span><span class="kc">False</span><span class="p">)</span></div>


<div class="viewcode-block" id="signbit"><a class="viewcode-back" href="../../../api_python/numpy/mindspore.numpy.signbit.html#mindspore.numpy.signbit">[docs]</a><span class="k">def</span> <span class="nf">signbit</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="n">dtype</span><span class="o">=</span><span class="kc">None</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Returns element-wise True where signbit is set (less than zero).</span>

<span class="sd">    Note:</span>
<span class="sd">        Numpy arguments `out`, `where`, `casting`, `order`, `subok`, `signature`, and</span>
<span class="sd">        `extobj` are not supported.</span>

<span class="sd">    Args:</span>
<span class="sd">        x (Union[int, float, bool, list, tuple, Tensor]): The input value(s).</span>
<span class="sd">        dtype (:class:`mindspore.dtype`, optional): Defaults to None. Overrides the dtype of the</span>
<span class="sd">            output Tensor.</span>

<span class="sd">    Returns:</span>
<span class="sd">        Tensor.</span>

<span class="sd">    Raises:</span>
<span class="sd">        TypeError: If input is not array_like or `dtype` is not `None` or `bool`.</span>

<span class="sd">    Supported Platforms:</span>
<span class="sd">        ``Ascend`` ``GPU`` ``CPU``</span>

<span class="sd">    Examples:</span>
<span class="sd">        &gt;&gt;&gt; import mindspore.numpy as np</span>
<span class="sd">        &gt;&gt;&gt; x = np.array([1, -2.3, 2.1]).astype(&#39;float32&#39;)</span>
<span class="sd">        &gt;&gt;&gt; output = np.signbit(x)</span>
<span class="sd">        &gt;&gt;&gt; print(output)</span>
<span class="sd">        [False  True False]</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="n">dtype</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">_check_same_type</span><span class="p">(</span><span class="n">dtype</span><span class="p">,</span> <span class="n">mstype</span><span class="o">.</span><span class="n">bool_</span><span class="p">):</span>
        <span class="n">_raise_type_error</span><span class="p">(</span><span class="s2">&quot;Casting was not allowed for signbit.&quot;</span><span class="p">)</span>
    <span class="n">x</span> <span class="o">=</span> <span class="n">_to_tensor</span><span class="p">(</span><span class="n">x</span><span class="p">)</span>
    <span class="n">res</span> <span class="o">=</span> <span class="n">F</span><span class="o">.</span><span class="n">less</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">dtype</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span> <span class="ow">and</span> <span class="ow">not</span> <span class="n">_check_same_type</span><span class="p">(</span><span class="n">F</span><span class="o">.</span><span class="n">dtype</span><span class="p">(</span><span class="n">res</span><span class="p">),</span> <span class="n">dtype</span><span class="p">):</span>
        <span class="n">res</span> <span class="o">=</span> <span class="n">F</span><span class="o">.</span><span class="n">cast</span><span class="p">(</span><span class="n">res</span><span class="p">,</span> <span class="n">dtype</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">res</span></div>


<div class="viewcode-block" id="sometrue"><a class="viewcode-back" href="../../../api_python/numpy/mindspore.numpy.sometrue.html#mindspore.numpy.sometrue">[docs]</a><span class="k">def</span> <span class="nf">sometrue</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="n">axis</span><span class="o">=</span><span class="kc">None</span><span class="p">,</span> <span class="n">keepdims</span><span class="o">=</span><span class="kc">False</span><span class="p">):</span>
    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">    Tests whether any array element along a given axis evaluates to True.</span>

<span class="sd">    Returns single boolean unless axis is not None</span>

<span class="sd">    Args:</span>
<span class="sd">        a (Union[int, float, bool, list, tuple, Tensor]): Input tensor or object that can be converted to an array.</span>
<span class="sd">        axis (Union[None, int, tuple(int)]): Axis or axes along which a logical OR reduction is</span>
<span class="sd">            performed. Default: None.</span>
<span class="sd">            If None, perform a logical OR over all the dimensions of the input array.</span>
<span class="sd">            If negative, it counts from the last to the first axis.</span>
<span class="sd">            If tuple of integers, a reduction is performed on multiple axes, instead of a single axis or</span>
<span class="sd">            all the axes as before.</span>
<span class="sd">        keepdims (bool): Default: False.</span>
<span class="sd">            If True, the axes which are reduced are left in the result as dimensions with size one.</span>
<span class="sd">            With this option, the result will broadcast correctly against the input array.</span>
<span class="sd">            If the default value is passed, then keepdims will not be passed through to the any method of</span>
<span class="sd">            sub-classes of ndarray, however any non-default value will be. If the sub-class method does not</span>
<span class="sd">            implement keepdims any exceptions will be raised.</span>

<span class="sd">    Returns:</span>
<span class="sd">        Returns single boolean unless axis is not None</span>

<span class="sd">    Raises:</span>
<span class="sd">        TypeError: If input is not array_like or `axis` is not int or tuple of integers or</span>
<span class="sd">            `keepdims` is not integer or `initial` is not scalar.</span>
<span class="sd">        ValueError: If any axis is out of range or duplicate axes exist.</span>

<span class="sd">    Supported Platforms:</span>
<span class="sd">        ``Ascend`` ``GPU`` ``CPU``</span>

<span class="sd">    Examples:</span>
<span class="sd">        &gt;&gt;&gt; import mindspore.numpy as np</span>
<span class="sd">        &gt;&gt;&gt; x = np.array([1, -2.3, 2.1]).astype(&#39;float32&#39;)</span>
<span class="sd">        &gt;&gt;&gt; output = np.sometrue(x)</span>
<span class="sd">        &gt;&gt;&gt; print(output)</span>
<span class="sd">        True</span>
<span class="sd">    &quot;&quot;&quot;</span>
    <span class="k">if</span> <span class="ow">not</span> <span class="nb">isinstance</span><span class="p">(</span><span class="n">keepdims</span><span class="p">,</span> <span class="nb">int</span><span class="p">):</span>
        <span class="n">_raise_type_error</span><span class="p">(</span><span class="s2">&quot;integer argument expected, but got &quot;</span><span class="p">,</span> <span class="n">keepdims</span><span class="p">)</span>
    <span class="k">if</span> <span class="n">axis</span> <span class="ow">is</span> <span class="ow">not</span> <span class="kc">None</span><span class="p">:</span>
        <span class="n">_check_axis_type</span><span class="p">(</span><span class="n">axis</span><span class="p">,</span> <span class="kc">True</span><span class="p">,</span> <span class="kc">True</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span>
        <span class="n">axis</span> <span class="o">=</span> <span class="n">_canonicalize_axis</span><span class="p">(</span><span class="n">axis</span><span class="p">,</span> <span class="n">a</span><span class="o">.</span><span class="n">ndim</span><span class="p">)</span>
    <span class="n">a</span> <span class="o">=</span> <span class="n">_to_tensor</span><span class="p">(</span><span class="n">a</span><span class="p">)</span>
    <span class="n">keepdims</span> <span class="o">=</span> <span class="n">keepdims</span> <span class="ow">not</span> <span class="ow">in</span> <span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="kc">False</span><span class="p">)</span>
    <span class="k">return</span> <span class="n">F</span><span class="o">.</span><span class="n">not_equal</span><span class="p">(</span><span class="n">a</span><span class="p">,</span> <span class="mi">0</span><span class="p">)</span><span class="o">.</span><span class="n">any</span><span class="p">(</span><span class="n">axis</span><span class="p">,</span> <span class="n">keepdims</span><span class="p">)</span></div>
</pre></div>

           </div>
           
          </div>
          <footer>

  <hr/>

  <div role="contentinfo">
    <p>
        &#169; Copyright 2021, MindSpore.

    </p>
  </div>
    
    
    
    Built with <a href="https://www.sphinx-doc.org/">Sphinx</a> using a
    
    <a href="https://github.com/readthedocs/sphinx_rtd_theme">theme</a>
    
    provided by <a href="https://readthedocs.org">Read the Docs</a>. 

</footer>
        </div>
      </div>

    </section>

  </div>
  

  <script type="text/javascript">
      jQuery(function () {
          SphinxRtdTheme.Navigation.enable(true);
      });
  </script>

  
  
    
   

</body>
</html>